package com.jackrain.nea.fc.cp.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.parser.Feature;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.jackrain.nea.config.Resources;
import com.jackrain.nea.exception.NDSException;
import com.jackrain.nea.fc.cp.api.CadUserSaveCmd;
import com.jackrain.nea.fc.cp.api.UserTokenCmd;
import com.jackrain.nea.fc.cp.mapper.UserTokenMapper;
import com.jackrain.nea.sys.CommandAdapter;
import com.jackrain.nea.util.ApplicationContextHandle;
import com.jackrain.nea.util.ValueHolder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.HashMap;

@Slf4j
@Component
@Service(protocol = "dubbo", validation = "true", version = "1.0", group = "cp")
public class UserTokenCmdImpl extends CommandAdapter implements UserTokenCmd{

    @Override
    public ValueHolder execute(HashMap map) throws NDSException {
        ValueHolder vh = new ValueHolder();
        JSONObject param = JSON.parseObject(JSON.toJSONStringWithDateFormat(map.get("param"), "yyyy-MM-dd HH:mm:ss", SerializerFeature.WriteMapNullValue), Feature.OrderedField);
//        log.debug("----------测试代码1-------------");
        UserTokenMapper userTokenMapper = ApplicationContextHandle.getBean(UserTokenMapper.class);
        HashMap hashMap = userTokenMapper.getUserToken(param.getString("user_code"), param.getString("pwd"));
//        log.debug("--------测试代码2----------");
        if(hashMap==null){
            vh.put("code", -1);
            vh.put("message", Resources.getMessage("未查询到数据"));
        }else {
            vh.put("data", hashMap);
            vh.put("code", 0);
            vh.put("message", Resources.getMessage("查询到数据"));
        }
//        log.debug("----------测试代码3-------------");
        return vh;
    }
}
